<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class BlogController extends BaseController{
	//添加微博
	public function add_post_json(){
		$blog=M('Blog');
		$blog->create();
		$data['title']=$_GET['title'];
		$data['content']=$_GET['content'];
		$data['customerid']=$_SESSION['customer']['id'];
		$res=$blog->add($data);
		if($res){
			M('customer')->where(array('id'=>$_SESSION['customer']['id']))->setInc('blogcount');
			$data=array(
				'error_no'=>10009,
				'msg'=>'发布成功',
				'status'=>1,
			);	
		}else{
			$data=array(
				'error_no'=>20009,
				'msg'=>'发布失败',
				'status'=>0,
			);
		}
		$this->Response($data,'json');
	}
	//查看微博
	public function view_json(){
		$blog=M('Blog');
		$blogid=$_GET['id'];
		$res=$blog->find($blogid);	
		if($res){		
			$data=array(
				'error_no'=>10010,
				'res'=>$res,
				'status'=>1,
			);
		}
		$this->Response($data,'json');
	}
	//获取微博列表
	public function list_json(){
		$blog=M('Blog');	
		$res=$blog->limit(10)->select();
		if($res){		
			$data=array(
				'error_no'=>10011,
				'msg'=>'微博列表',
				'res'=>$res,
				'status'=>1,
			);
		}else{
			$data=array(
				'error_no'=>20011,
				'msg'=>'获取列表失败',
				'status'=>0,			
			);
		}
		
		$this->Response($data,'json');

	}
	//删除微博
	public function del_get(){		
		$blogid=$_GET['id'];
		$res=M('Blog')->delete($blogid);	
		if($res){		
			$data=array(
				'error_no'=>10011,
				'msg'=>'删除成功',
				'status'=>1,
			);
		}else{
			$data=array(
				'error_no'=>20011,
				'msg'=>'删除失败',
				'status'=>0,
			);
		}
		$this->Response($data,'json');

	}

}